{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cfdd9796",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "data_W1_AFE=pd.read_csv(\"5G_F37_0603_0609.csv\") #改\n",
    "# data_W2_AFE=pd.read_csv(\"compdata/4G5G_Data/Train_Data/5g_pm_20210623_20210630_AFE97F546A10368F.csv\",encoding='gbk')#改\n",
    "data_W1_AFE.head()\n",
    "data_W1_AFE= pd.DataFrame(data_W1_AFE)\n",
    "data_W1_AFE_PUSCH=data_W1_AFE[['UserLabel','上行利用率PUSCH','TimeStamp']]\n",
    "data_W1_AFE_UserLabel=data_W1_AFE['UserLabel']\n",
    "from collections import Counter\n",
    "data_W1_AFE_UserLabel_zhonglei=Counter(data_W1_AFE_UserLabel)\n",
    "UserLabel_name=[]\n",
    "num=0\n",
    "for name in data_W1_AFE_UserLabel_zhonglei.keys():\n",
    "    UserLabel_name.append(name)\n",
    "    num=num+1\n",
    "print(num)\n",
    "d = {'上行利用率PUSCH': [1], '下行利用率PDSCH':[1],'下行利用率PDCCH':[1],'上行流量':[1],'下行流量':[1],'有数据传输的RRC数':[1]}\n",
    "df = pd.DataFrame(data=d)\n",
    "a=0\n",
    "b2=0\n",
    "while a<2052:#改\n",
    "    b=data_W1_AFE.loc[data_W1_AFE[\"UserLabel\"] == UserLabel_name[a],].上行利用率PUSCH.sum()\n",
    "    c=b/data_W1_AFE_UserLabel_zhonglei[UserLabel_name[a]]\n",
    "    bb=data_W1_AFE.loc[data_W1_AFE[\"UserLabel\"] == UserLabel_name[a],].下行利用率PDSCH.sum()\n",
    "    cc=bb/data_W1_AFE_UserLabel_zhonglei[UserLabel_name[a]]\n",
    "    bbb=data_W1_AFE.loc[data_W1_AFE[\"UserLabel\"] == UserLabel_name[a],].下行利用率PDCCH.sum()\n",
    "    ccc=bbb/data_W1_AFE_UserLabel_zhonglei[UserLabel_name[a]]\n",
    "    bbbb=data_W1_AFE.loc[data_W1_AFE[\"UserLabel\"] == UserLabel_name[a],].上行流量.sum()\n",
    "    cccc=bbbb/data_W1_AFE_UserLabel_zhonglei[UserLabel_name[a]]    \n",
    "    bbbbb=data_W1_AFE.loc[data_W1_AFE[\"UserLabel\"] == UserLabel_name[a],].下行流量.sum()\n",
    "    ccccc=bbbbb/data_W1_AFE_UserLabel_zhonglei[UserLabel_name[a]] \n",
    "    bbbbbb=data_W1_AFE.loc[data_W1_AFE[\"UserLabel\"] == UserLabel_name[a],].有数据传输的RRC数.sum()\n",
    "    cccccc=bbbbbb/data_W1_AFE_UserLabel_zhonglei[UserLabel_name[a]]\n",
    "    df=df.append(pd.DataFrame({'上行利用率PUSCH':c, '下行利用率PDSCH':cc, '下行利用率PDCCH':ccc,'上行流量':cccc,'下行流量':ccccc,'有数据传输的RRC数':cccccc}, index=[UserLabel_name[a]]))\n",
    "    a=a+1\n",
    "df_w1=df.drop([0])  \n",
    "indexs_name = df_w1._stat_axis.values.tolist()\n",
    "df_w1=df_w1.sort_values(by=\"上行利用率PUSCH\" , ascending=False)\n",
    "df_w1['name'] =indexs_name\n",
    "paiming= pd.DataFrame(index=df_w1.index, columns=df_w1.columns)\n",
    "paiming.head()   \n",
    "df_w1.iloc[0,6]\n",
    "paiming['name']=indexs_name\n",
    "a=0\n",
    "while a<2000*0.3:#改\n",
    "    paiming.loc[paiming['name']==df_w1.iloc[a,6],'上行利用率PUSCH']=1\n",
    "    a=a+1\n",
    "# print(paiming)\n",
    "df_w1=df_w1.sort_values(by=\"下行利用率PDSCH\" , ascending=False)\n",
    "a=0\n",
    "while a<2000*0.3:#改\n",
    "    paiming.loc[paiming['name']==df_w1.iloc[a,6],'下行利用率PDSCH']=1\n",
    "    a=a+1\n",
    "\n",
    "df_w1=df_w1.sort_values(by=\"下行利用率PDCCH\" , ascending=False)\n",
    "a=0\n",
    "while a<2000*0.3:#改\n",
    "    paiming.loc[paiming['name']==df_w1.iloc[a,6],'下行利用率PDCCH']=1\n",
    "    a=a+1\n",
    "    \n",
    "    \n",
    "df_w1=df_w1.sort_values(by=\"上行流量\" , ascending=False)\n",
    "a=0\n",
    "while a<2000*0.3:#改\n",
    "    paiming.loc[paiming['name']==df_w1.iloc[a,6],'上行流量']=1\n",
    "    a=a+1\n",
    "\n",
    "df_w1=df_w1.sort_values(by=\"下行流量\" , ascending=False)\n",
    "a=0\n",
    "while a<2000*0.3:#改\n",
    "    paiming.loc[paiming['name']==df_w1.iloc[a,6],'下行流量']=1\n",
    "    a=a+1\n",
    "\n",
    "\n",
    "df_w1=df_w1.sort_values(by=\"有数据传输的RRC数\" , ascending=False)\n",
    "a=0\n",
    "while a<2000*0.3:#改\n",
    "    paiming.loc[paiming['name']==df_w1.iloc[a,6],'有数据传输的RRC数']=1\n",
    "    a=a+1\n",
    "\n",
    "paiming=paiming.fillna(0)\n",
    "paiming2=paiming\n",
    "name1=paiming['name']\n",
    "name2=paiming2['name']\n",
    "intersected_paiming = pd.merge(name1, name2, how='inner')\n",
    "\n",
    "jiaojinamegeshu=intersected_paiming.iloc[:,0].size\n",
    "\n",
    "i=0\n",
    "j=0\n",
    "zhibiao=['上行利用率PUSCH', '下行利用率PDSCH', '下行利用率PDCCH','上行流量','下行流量','有数据传输的RRC数']\n",
    "paiming3=intersected_paiming\n",
    "# paiming3.drop('上行利用率PUSCH, 下行利用率PDSCH, 下行利用率PDCCH, 上行流量, 下行流量, 有数据传输的RRC数',axis = 1,inplace = True) #axis参数默认为0\n",
    "paiming3['上行利用率PUSCH']=''\n",
    "paiming3['下行利用率PDSCH']=''\n",
    "paiming3['下行利用率PDCCH']=''\n",
    "paiming3['上行流量']=''\n",
    "paiming3['下行流量']=''\n",
    "paiming3['有数据传输的RRC数']=''\n",
    "i=0\n",
    "j=0\n",
    "# print(paiming.loc[paiming['name']==intersected_paiming.iloc[i,0],zhibiao[j]]*paiming2.loc[paiming2['name']==intersected_paiming.iloc[i,0],zhibiao[j]].values)\n",
    "while i<jiaojinamegeshu:\n",
    "    j=0\n",
    "    while j<6:\n",
    "        paiming3.loc[paiming3['name']==intersected_paiming.iloc[i,0],zhibiao[j]]=paiming.loc[paiming['name'].values==intersected_paiming.iloc[i,0],zhibiao[j]].values*paiming2.loc[paiming2['name']==intersected_paiming.iloc[i,0],zhibiao[j]].values\n",
    "        j=j+1\n",
    "    i=i+1\n",
    "# print(paiming3)\n",
    "paiming3['sum'] = paiming3.iloc[:,1:7].sum(axis=1)\n",
    "print(paiming3)\n",
    "a=[0]*1\n",
    "b=0\n",
    "while b<2000:#改\n",
    "    if(paiming3.iloc[b,7]>0):\n",
    "        a.append(paiming3.iloc[b,0])\n",
    "    b=b+1\n",
    "a.remove(0)\n",
    "print(a)    \n",
    "import random\n",
    "random.sample(a, 200)\n",
    "#注释：paiming2要改为全部第二周的数据 所有的10要改为小区数量"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "py37",
   "language": "python",
   "name": "py37"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
